<?php

class NewController extends ControllerBase
{
	public function hideAction($id = 0)
	{
		$this->view->setRenderLevel(Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
		
		$new = News::findFirstById($id);
		
		if (!$new) {
			echo 'error';
		}
		
		$new->del_flg = 1;
		
		if ($new->save()) {
			echo 'success';
		} else {
			echo 'error';
		}
	}
	
	public function insertAction() {
		$this->view->setRenderLevel(Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
		
		$id = rand(1, 39);
		
		$first = News::findFirstById($id);
		
		$new = new News();
		
		$new->guid = $first->guid;
		$new->title = $first->title;
		$new->description_link = $first->description_link;
		$new->description_text = $first->description_text;
		$new->public_date = $first->public_date;
		$new->link = $first->link;
		$new->del_flg = 0;
		$new->created = date('Y-m-d H:i:s');
		
		if ($new->save()) {
			echo 'success';
		} else {
			echo 'error';
		}
	}
}